<include file="Public/common1" />
<style>#table .btn-primary{ margin-bottom: 5px; }</style>
<block name="content">
    <div class="page-header"><h1>销售管理 &gt;订单列表</h1></div>
    <form id="form" action="{:U('orderList',['p'=>1])}" >
        <div class="col-xs-12 clearfix">
            <div class="col-xs-3">
                <label for="" class="col-xs-4">订单号</label>
                <div class="col-xs-8"><input name="order_num" value="<if condition="$_GET['order_num']">{$_GET['order_num']}</if>" type="text" class="form-control" /></div>
            </div>
            <div class="col-xs-3">
                <label for="" class="col-xs-4">线路名称</label>
                <div class="col-xs-8"><input name="line_name" type="text" value="<if condition="$_GET['line_name']">{$_GET['line_name']|urldecode = ###}</if>" class="form-control" /></div>
            </div>
            <div class="col-xs-3">
                <label for="" class="col-xs-4">出发城市</label>
                <div class="col-xs-8"><input name="set_out" type="text" value="<if condition="$_GET['set_out']">{$_GET['set_out'] |urldecode = ### }</if>" class="form-control" class="form-control" /></div>
            </div>
            <div class="col-xs-3">
                <label for="" class="col-xs-4">订单状态</label>
                <div class="col-xs-8">
                    <select name="order_status">
                        <option value="1,3">全部</option>
                        <option value="1,3" <if condition="$_GET['order_status'] == '1,3'">selected</if>>已支付</option>
                        <option value="-5" <if condition="$_GET['order_status'] == -5">selected</if>>拒绝退款</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12 clearfix mt-15">
            <div class="col-xs-3">
                <label for="" class="col-xs-4">游客姓名</label>
                <div class="col-xs-8"><input  name="tourists_name" type="text" value="<if condition="$_GET['tourists_name']">{$_GET['tourists_name'] |urldecode = ###}</if>" class="form-control" class="form-control" /></div>
            </div>

            <div class="col-xs-3">
                <label for="" class="col-xs-4">联系方式</label>
                <div class="col-xs-8"><input type="text" name="tourists_phone"  value="<if condition="$_GET['tourists_phone']">{$_GET['tourists_phone']}</if>" class="form-control" class="form-control" /></div>
            </div>
            <!-- 分销商 -->
            <div class="col-xs-3">
                <label for="" class="col-xs-4">分销商</label>
                <div class="col-xs-8">
                    <select name="reseller_id">
                        <option value="">全部</option>
                        <foreach name="reseller" item="v">
                            <option value="{$v['reseller_id']}" <if condition="$v['reseller_id'] == $_GET['reseller_id']">selected</if>>{$v['reseller_name']}</option>
                        </foreach>
                    </select>
                </div>
            </div>
            <!-- 直营门店 -->
            <if condition="shop">
                <div class="col-xs-3">
                    <label for="" class="col-xs-4">直营门店</label>
                    <div class="col-xs-8">
                        <select name="shop_id">
                            <option value="">全部</option>
                            <foreach name="shop" item="v">
                                <option value="{$v['reseller_id']}" <if condition="$v['reseller_id'] == $_GET['shop_id']">selected</if>>{$v['reseller_name']}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
            </if>
        </div>

        <div class="col-xs-12 clearfix mt-15">
            <div class="col-xs-6">
                <label for="" class="col-xs-2">下单时间</label>
                <div class="col-xs-4"><input name="start_time" id="start" placeholder="开始时间" value="<if condition="$_GET['start_time']">{$_GET['start_time'] |urldecode = ###}</if>" class="form-control" class="form-control" /></div>
                <!-- <div class="col-xs-1"></div> -->
                <div class="col-xs-4"><input name="end_time" id="end" placeholder="结束时间" value="<if condition="$_GET['end_time']">{$_GET['end_time'] |urldecode = ###}</if>" class="form-control" class="form-control" /></div>
            </div>


            <!-- <div class="col-xs-3">
                <label for="" class="col-xs-4">销售人</label>
                <div class="col-xs-8">
                    <select name="sales_id">
                        <option value="">全部</option>
                        <foreach name="staff" item="v">
                            <option value="{$v['reseller_id']}" <if condition="$v['reseller_id'] == $_GET['sales_id']">selected</if>>{$v['reseller_name']}</option>
                        </foreach>
                    </select>
                </div>
            </div> -->

        </div>
        <div class="col-xs-12 clearfix mt-15">
            <div class="col-xs-9">
                <button type="button" id="export" class="btn btn-primary" style="margin-right: 10px">导出</button>
                <button class="btn btn-primary" style="margin-right: 10px" >查询</button>
                <div class="dropdown" style="display: inline-block">
                    <button type="button" class="btn btn-primary dropdown-toggle"  id="dropdownMenu1" data-toggle="dropdown">筛选<span class="caret"></span></button>
                    <ul id="menuList" class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1" style="padding:10px;">
                        <li><input type="checkbox" class="filtrate" checked="" value="0" id="filtrate_1"><label for="filtrate_1">订单号</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="1" id="filtrate_2"><label for="filtrate_2">线路名称</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="2" id="filtrate_3"><label for="filtrate_3">团号</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="3" id="filtrate_4"><label for="filtrate_4">游客姓名</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="4" id="filtrate_5"><label for="filtrate_5">联系方式</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="5" id="filtrate_6"><label for="filtrate_6">预订人数</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="6" id="filtrate_7"><label for="filtrate_7">销售单价</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="7" id="filtrate_8"><label for="filtrate_8">订单总额</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="8" id="filtrate_9"><label for="filtrate_9">直营门店</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="9" id="filtrate_10"><label for="filtrate_10">销售人</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="10" id="filtrate_11"><label for="filtrate_11">出发城市</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="11" id="filtrate_12"><label for="filtrate_12">下单时间</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="12" id="filtrate_13"><label for="filtrate_13">分销商</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="13" id="filtrate_14"><label for="filtrate_14">余位</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="14" id="filtrate_15"><label for="filtrate_15">状态</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="15" id="filtrate_16"><label for="filtrate_16">审核状态</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="16" id="filtrate_17"><label for="filtrate_17">负责人</label></li>
                        <li><input type="checkbox" class="filtrate" checked="" value="17" id="filtrate_18"><label for="filtrate_18">操作</label></li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-3 text-right ">销售总额：<span class="text-danger">&#165;{$orderList['total_money']}</span>
            </div>
        </div>
    </form>

    <table id="table" class="table table-striped  table-bordered table-hover table-condensed  mt-15">
        <thead>
            <tr>
                <th>订单号</th>
                <th>线路名称</th>
                <th>団号</th>
                <th>游客姓名</th>
                <th>联系方式</th>
                <th>预定人数</th>
                <th>销售单价</th>

                <th>订单总额</th>
                <th>直营门店</th>

                <th>销售人</th>
                <th>出发城市</th>
                <th>下单时间</th>
                <th>分销商</th>
                <th>余位</th>
                <th>团状态</th>
                <th>状态</th>
                <th>审核状态</th>
                <th>负责人</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <foreach name="orderList['list']" item="v">
            <tr>
                <td>{$v['order_num']}</td>
                <td>{$v['line_name']}</td>
                <td>{$v['group_num']}</td>
                <td>{$v['tourists_name']}</td>
                <td>{$v['tourists_phone']}</td>
                <td>
                    预订人数：{$v['total_num']}<br/>
                    大：{$v['adult_num']}<br/>
                    小：{$v['child_num']}<br/>
                   <!-- 老：{$v['oldMan_num']}-->
                </td>
                <td>大：{$v['adult_price']}<br/>
                    小：{$v['child_price']}<br/>
                  <!--  老：{$v['oldman_price']}-->
                </td>
                <td>{$v['total_money']}</td>
                <td>{$v['store']}</td>
                <td>{$v['sales']}</td>
                <td>{$v['set_out']}</td>
                <td>{$v['create_time']}</td>
                <td>{$v['reseller']}</td>
                <td>{$v['leave_num']}</td>
                <td>{$v['group_text']}</td>
                {$v['html']}
                <td>{$v['manager']}</td>
                <td>
                    <if condition="$v['order_status'] == -1">
                        <button class="btn btn-primary"  onclick="cancel({$v['order_id']})">取消</button>
                    </if>
                    <!-- 有权限and订单已审核and(待成团or已成团) -->
                    <if condition="($v['order_status'] == 3) && ($v['group_status'] == 0 || $v['group_status'] == 1 || $v['group_status'] == -1)"><button class="btn btn-primary" onclick="refuse('{$v['order_num']}', {$v['order_id']})">退款</button></if>

                    <button class="btn btn-primary"  onclick="openDetail({$v['order_id']})">详情</button><br/>

                    <if condition="$v['order_status'] == 1">
                        <button class="btn btn-primary" onclick="passAduit({$v['order_id']}, '{$v['order_num']}')">通过审核</button>
                        <button class="btn btn-primary" onclick="refuseAduit({$v['order_id']}, '{$v['order_num']}')">拒绝审核</button>
                    </if>

                </td>
            </tr>
            </foreach>
        </tbody>
    </table>
    <ul class="pagination pull-right">{$orderList['show']}</ul>
</block>
<block name="js">
<script src="__JS__/jedate/jedate.js"></script>
<script>
/**
 * 订单审核
 * @param  {[int]} oid    [订单id]
 * @param  {[string]} num [订单编号]
 */
function passAduit(oid, num){
    layer.confirm('订单号：'+num,{
        btn : ['通过', '返回'],
        title: '订单审核'
    },function(){
        layer.closeAll();
        aduitRequest(oid, 1);
    })
}

/**
 * 订单审核
 * @param  {[int]} oid    [订单id]
 * @param  {[string]} num [订单编号]
 */
function refuseAduit(oid, num){
    layer.confirm('订单号：'+num,{
        btn : [ '拒绝', '返回'],
        title: '订单审核'
    },function(){
        layer.closeAll();
        aduitRequest(oid, 2);
    })
}

/**
 * 发送点单审核请求
 * @param  {[int]} oid [订单id]
 * @param  {[int]} type [1：通过  2：拒绝]
 */
function aduitRequest(oid, type){
    $.post('{:U('aduit')}', {order_id : oid, type : type}, function(data){
        if(data.status ==1 ){
            layer.msg('操作成功', {icon: 6})
            setTimeout(function(){
                location.reload();
            }, 1000)
        }else{
            layer.msg('操作失败', {icon: 5})
        }
    }, 'json' )
}

//筛选
$('#menuList').on('change', '.filtrate', function(){
    var index = $(this).val();
    if($(this).prop('checked')){
        $('#table tr').each(function(i,n){  $(n).children().eq(index).show(); })
    }else{
        $('#table tr').each(function(i,n){  $(n).children().eq(index).hide();})
    }
})

$form = $('#form');
//导出excel
$('#export').click(function(){
    $form.attr('action', '{:U('exportExcels')}');
    $form.submit();
    $form.attr('action', '');
})

dateFormat($('#start'), 'YYYY-MM-DD');
dateFormat($('#end'), 'YYYY-MM-DD');

/**
 * 绑定日期选择器
 * @param  {[obj]}    obj        [元素]
 * @param  {[string]} dateFormat [时间格式]
 */
function dateFormat(obj, dateFormat){
    jeDate({
        dateCell: '#'+$(obj).attr('id'),
        format: dateFormat,
        isinitVal:false,
        isTime:true, //isClear:false,
        okfun:function(val){
        }
    });
}

/**
 * 订单取消
 * @param  {[int]}    orderId     [订单id]
 */
function cancel(oId){
    layer.confirm('将此订单放入订单回收站?',
    { btn: ['确认', '取消'] },function(){
        $.post('{:U('cancel')}',{order_id: oId}, function(data){
            layer.msg(data.msg);
            if(data.status == 1){
                setTimeout(function(){
                    location.reload();
                },1000)
                return ;
            }
        },'json')
    })
}

/**
 * 打开订单详情页面
 * @param  {[int]}    orderId     [订单id]
 */
function openDetail(oId){
    layer.open({
        type: 2,
        area: ['100%','100%'],
        title: '订单详情',
        content: '/Operator/Index/orderDetail/order_id/'+oId,
    })
}

/**
 * 退款
 * @param  {[string]}    orderNum     [订单编号]
 * @param  {[int]}    oId     [订单id]
 */
function refuse(orderNum, oId){
    layer.open({
        type: 2,
        area: ['400px', '300px'],
        title: '订单详情',
        content: '/Operator/SaleManger/refuseHtml/orderNum/'+orderNum+'/orderId/'+oId,
    })
}

/**
 * 退款
 * @param  {[string]}    orderNum     [订单编号]
 * @param  {[int]}    oId     [订单id]
 */
// function refuse(orderNum, oId){
//     layer.confirm('更改订单状态为待退款?',
//     { btn: ['确认', '取消'] },function(){
//         $.post('{:U('toWaitRefund')}',{order_id: oId}, function(data){
//             if(data.status == 1){
//                 location.reload();
//                 return ;
//             }
//             layer.msg('操作失败');
//         },'json')
//     })
// }

/**
 * 确认支付
 * @param  {[int]}    orderId     [订单id]
 */
function confirmPay(oId){
    layer.confirm('更改该订单状态为已支付?',
    { btn: ['确认', '取消'] },function(){
        $.post('{:U('confirmPay')}',{order_id: oId}, function(data){
            if(data.status == 1){
                location.reload();
                return ;
            }
            layer.msg('操作失败');
        },'json')
    })
}

</script>
</block>
